<!-- 
	15905697042
	1234
-->
<template>
	<view class="set">
		<view class="cu-list menu-avatar">
			<view class="cu-item" :class="modalName == 'move-box-' + index ? 'move-cur' : ''" v-for="(item, index) in setList"
			 :key="index" @tap="navTo(item.url)" :data-target="'move-box-' + index">
				<!-- 这里差了个icon -->
				<view class="cu-avatar round lg" :style="[{backgroundImage: `url(${baseUrl}/appIcon/notify/${item.avatar})` }]"></view>
				<!-- /这里差了个icon -->
				<!-- 这里是名字 -->
				<view class="content">
					<view class="text-grey">{{ item.title }}</view>
					<view v-if="item.num > 0" class="text-gray text-sm">
						<text class="cuIcon-infofill text-red  margin-right-xs"></text>
						{{ item.msg }}
					</view>
				</view>
				<!-- /这里是名字 -->
				<!-- 这里是消息 -->
				<view class="action">
					<view class="text-grey text-xs">{{item.time | filterTime }}</view>
					<view class="cu-tag round bg-red sm" v-if="item.num > 0">{{ item.num }}</view>
				</view>
				<view class="cell-more iconfont iconyou"></view>
				<view class="move">
					<view class="bg-grey">置顶</view>
					<view class="bg-red">删除</view>
				</view>
				<!-- /这里是消息 -->
			</view>
<!-- /////////////////////////////////////////// -->
			<!-- 这里是活动签到 -->
			<navigator class="cu-item" url="../qdome/qd_demo" open-type="navigate">
				<view class="cu-avatar round lg" :style="[{backgroundImage: `url()` }]"></view>
				<view class="content">
					<view class="text-grey">活动签到</view>
				</view>
				<!--  -->
				<view class="cell-more iconfont iconyou"></view>
			</navigator>
			<!-- 这里是活动签到 -->

			<!-- 这里是老年大学 -->
			<navigator class="cu-item" url="../oldxue/oldxue" open-type="navigate">
				<view class="cu-avatar round lg" :style="[{backgroundImage: `url()` }]"></view>
				<view class="content">
					<view class="text-grey">老年大学</view>
				</view>
				<!--  -->
				<view class="cell-more iconfont iconyou"></view>
			</navigator>
			<!-- 这里是老年大学 -->
		</view>
<!-- ////////////////////////////////////////// -->

		<!-- modal -->
		<!-- 选择颜色模态框 -->
		<view class="cu-modal" :class="{ show: colorModal }">
			<view class="cu-dialog">
				<view class="cu-bar justify-end solid-bottom">
					<view class="content">选择颜色</view>
					<view class="action" @tap="colorModal = false"><text class="cuIcon-close text-red"></text></view>
				</view>
				<view class="grid col-5 padding">
					<view class="padding-xs" v-for="(item, index) in themeList" :key="index" @tap="SetColor(item)" :data-color="item.name">
						<view class="padding-tb radius" :class="'bg-' + item.name">{{ item.title }}</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	// 活动签到
	// import QianDao from "@/components/qian-dao/qian-dao.vue";

	import {
		notifyUnRreadCount
	} from '@/api/userInfo';
	//var dateUtils = require('/common/util.js').dateUtils;
	import {
		friendlyDate,
		dateUtils
	} from '@/common/util.js';
	import {
		mapMutations
	} from 'vuex';

	export default {
		// components: {
		// 	// 签到
		// 	QianDao,
		// },
		data() {
			return {
				isVersionUpgradeShow: false,
				loadProgress: 0,
				CustomBar: this.CustomBar,
				user: {},
				setList: [],
				styleUserIsOpen: this.$mSettingConfig.styleUserIsOpen,
				notifyChecked: false,
				isNewVersion: false,
				colorModal: false,
				themeList: this.$mConstDataConfig.themeList,
				msgRemind: {},
				modalName: null,
				listTouchStart: 0,
				listTouchDirection: null,
				baseUrl: this.$mConfig.baseUrl,

				// 打卡活动
				// 当前的日期
				date: "",

				// 存放时间的key值
				time_key: "",
				signToday: function() {
					this.isSigned = true;
					this.dates[this.day].isSigned = true;
				},
			};
		},
		filters: {
			filterTime(val) {
				return val ? friendlyDate(dateUtils.parse(val)) : ''
			}
		},
		onLoad() {
			this.initData();
		},
		onPullDownRefresh() {
			this.setList.length = 0;
			this.getLastMegInfo('refresh');
		},
		methods: {
			// 日期改变时触发
			date_change_fun(date) {
				// 更新日期
				this.date = date;

				// 清空已经签到的列表
				this.list = [];

				// 根据日期获取已经签到的列表然后赋值
				// 存放时间的key值
				let time_key = this.time_key;
				if (time_key) {
					this.list.push({
						time: "01"
					});
				} else {
					this.list.push("01");
				}
			},
			...mapMutations(['setNotifyNum']),
			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX;
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > 0 ? 'right' : 'left';
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target;
				} else {
					this.modalName = null;
				}
				this.listTouchDirection = null;
				console.log('this.modalName: ' + this.modalName);
			},
			// 初始化数据
			initData() {
				this.userInfo = uni.getStorageSync('userInfo');
				this.getLastMegInfo();
			},
			// 获取消息提醒
			async getLastMegInfo(type) {
				const params = {};
				let corpId = 10;
				if (this.userInfo.corpId) corpId = this.userInfo.corpId;
				let cstmIds = 0;
				if (this.userInfo && this.userInfo.userId && this.userInfo.cstmIds) cstmIds = this.userInfo.userId + ',' + this.userInfo
					.cstmIds;

				let url = `${notifyUnRreadCount}`;
				params.userId = this.userInfo && this.userInfo.userId;
				params.corpId = corpId;
				params.cstmIds = cstmIds;

				await this.$http
					.get(url, params)
					.then(async r => {
						console.log('消息提醒: ' + JSON.stringify(r.data));
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
						//this.loadingType = r.data.length == 10 ? 'more' : 'nomore';
						//this.notifyList = [...this.notifyList,...r.data];

						for (let i = 0; i < 13; i++) {
							if (i === 0) {
								let item = {
									msgType: 9,
									title: '围栏告警',
									url: '/pages/zhyl/remind/remind?msgType=9',
									type: 'childtx',
									num: r.data.fenceCount,
									msg: r.data.fenceMsg,
									time: r.data.fenceTime,
									avatar: 'gh0.png'
								};
								this.setList.push(item);
							} else if (i === 1) {
								let item = {
									msgType: 4,
									title: '健康预警',
									url: '/pages/zhyl/remind/remind?msgType=4',
									type: 'childtx',
									num: r.data.healthCount,
									msg: r.data.healthMsg,
									time: r.data.healthTime,
									avatar: 'gh2.png'
								};
								this.setList.push(item);
							} else if (i === 2) {
								let item = {
									msgType: 1,
									title: '腕表预警',
									url: '/pages/zhyl/remind/remind?msgType=1',
									type: 'childtx',
									num: r.data.watchCount,
									msg: r.data.watchMsg,
									time: r.data.watchTime,
									avatar: 'gh3.png'
								};
								this.setList.push(item);
							} else if (i === 3) {
								let item = {
									msgType: 14,
									title: '用药提醒',
									url: '/pages/zhyl/remind/remind?msgType=14',
									type: 'childtx',
									num: r.data.drugCount,
									msg: r.data.drugMsg,
									time: r.data.drugTime,
									avatar: 'gh1.png'
								};
								this.setList.push(item);
							} else if (i === 4) {
								let item = {
									msgType: 13,
									title: '活动提醒',
									url: '/pages/zhyl/remind/remind?msgType=13',
									type: 'childtx',
									num: r.data.activityCount,
									msg: r.data.activityMsg,
									time: r.data.activityTime,
									avatar: 'gh4.png'
								};
								this.setList.push(item);
							} else if (i === 5) {
								let item = {
									msgType: 15,
									title: '生日提醒',
									url: '/pages/zhyl/remind/remind?msgType=15',
									type: 'childtx',
									num: r.data.birthdayCount,
									msg: r.data.birthdayMsg,
									time: r.data.birthdayTime,
									avatar: 'gh6.png'
								};
								this.setList.push(item);
							} else if (i === 6) {
								/*
								let item = {
									msgType: 2,
									title: '关怀提醒',
									url: '/pages/zhyl/remind/remind?msgType=2',
									type: 'childtx',
									num: r.data.ghCount,
									msg: r.data.ghMsg,
									time: r.data.ghTime,
									avatar : 'gh5.png'
								};
								this.setList.push(item);*/
							}
						}

					})
					.catch(e => {
						this.loading = false;
						if (type === 'refresh') {
							uni.stopPullDownRefresh();
						}
						//console.log("通知错误: " + JSON.stringify(e));
					});
			},
			// 通用跳转
			navTo(route) {
				if (!route) return;
				if (route === 'clearCache') {
					uni.showModal({
						content: '确定要清除缓存吗',
						success: e => {
							if (e.confirm) {
								uni.clearStorageSync();
								this.setList[5].content = '0 kb';
								this.$mStore.commit('login', this.user);
								this.$mHelper.toast('清除缓存成功');
							}
						}
					});
					return;
				} else if (route === 'versionUpgrade') {
					this.isVersionUpgradeShow = true;
					if (this.isNewVersion) {
						this.$mHelper.toast('已经是最新版本');
					}
					return;
				}
				this.$mRouter.push({
					route
				});
			},
			// 退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: e => {
						if (e.confirm) {
							this.$mStore.commit('logout');
							uni.reLaunch({
								url: '/pages/profile/profile'
							});
						}
					}
				});
			},
			showColorModal() {
				this.colorModal = true;
			},
			SetColor(item) {
				this.colorModal = false;
				this.themeColor = item;
				this.$mStore.commit('setThemeColor', item);
			}
		}
	};
</script>
<style lang="scss">
	page {
		background: $page-color-base;
	}

	.set {
		padding: $spacing-base 0;
	}

	.cu-list.card-menu {
		margin: $spacing-base 0;

		.title {
			margin-left: $spacing-base;
		}
	}
</style>
